var requirejs = require(<%= rjs_path.to_s.dump %>)
var baseConfig = <%=
cdn_pattern = Regexp.new("\\Ahttps?://")

modifiedHash = build_config.select { |k, _| k != "modules" }
pathsHash = modifiedHash["paths"]

case loader
  when :requirejs
    modifiedHash['dir'] = build_dir.to_s
  when :almond
    almond_module = build_config['modules'][0]
    modifiedHash.merge!(almond_module)
    modifiedHash['out'] = build_dir + (module_name_for(almond_module) + '.js')
end

modifiedHash["paths"] = Hash[
  pathsHash.map do |k, v|
    [k, v.is_a?(Array) || cdn_pattern.match(v) ? "empty:" : v]
  end
] if !pathsHash.nil?

JSON.pretty_generate(modifiedHash)
%>;

<% unless loader == :almond %>
baseConfig.modules = [
<% build_config["modules"].each do |m| %>
  <%= JSON.pretty_generate(m) %>,
<% end %>
];
<% end %>

requirejs.optimize(baseConfig);
